home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / ghostscript / 8.64 / lib / printafm.ps < prev    next >
Encoding:
Text File  |  2009-04-17  |  3.7 KB  |  175 lines

  1. %!
  2. % written by James Clark <jjc@jclark.uucp>
  3. % print an afm file on the standard output
  4. % usage is `fontname printafm' eg `/Times-Roman printafm'
  5.  
  6. % From the `dvitops' distribution, which included this notice:
  7. % dvitops is not copyrighted; you can do with it exactly as you please.
  8. % I would, however, ask that if you make improvements or modifications,
  9. % you ask me before distributing them to others.
  10.  
  11. % Altered by d.love@dl.ac.uk to produce input for Rokicki's afm2tfm,
  12. % which groks the format of the Adobe AFMs.
  13.  
  14. % $Id: printafm.ps 8779 2008-05-27 17:07:40Z alexcher $
  15. % Modified by L. Peter Deutsch 9/14/93:
  16. %   uses Ghostscript's =only procedure to replace 'buf cvs print'.
  17. % Modified by L. Peter Deutsch 9/6/95:
  18. %   uses Ghostscript's shellarguments facility to accept the font name
  19. %     on the command line.
  20.  
  21. % Altered my master@iaas.msu.ru to work with fonts of more than 256 glyphs
  22. % and avoid FSType output. Also print a comment with UniqueID of the font.
  23.  
  24. /onechar 1 string def
  25.  
  26. % c toupper - c
  27. /toupper {
  28.     dup dup 8#141 ge exch 8#172 le and { 
  29.         8#40 sub
  30.     } if
  31. } bind def
  32.  
  33. % print unencoded character metric data lines for glyphs in `v' array
  34. % and reset `v' -
  35. /printv {
  36.     % define a new font with v as its encoding vector
  37.     currentfont maxlength dict /f exch def
  38.     currentfont {
  39.         exch dup dup /FID ne exch /Encoding ne and { 
  40.             exch f 3 1 roll put
  41.         } { 
  42.             pop pop 
  43.         } ifelse
  44.     } forall
  45.     f /Encoding v put
  46.     f /FontName /temp put
  47.     % make this new font the current font
  48.     /temp f definefont setfont
  49.     % print a entry for each character not in old vector
  50.     /e currentfont /Encoding get def
  51.     0 1 255 {
  52.         dup e exch get
  53.         dup dup /.notdef ne exch s exch known not and { 
  54.             exch -1 printmetric
  55.         } { 
  56.             pop pop
  57.         } ifelse
  58.     } for
  59.     0 1 255 {
  60.         v exch /.notdef put
  61.     } for
  62. } bind def
  63.  
  64. % printcharmetrics -
  65.  
  66. /printcharmetrics {
  67.     (StartCharMetrics ) print
  68.     currentfont /CharStrings get dup length exch /.notdef known { 1 sub } if =
  69.     currentfont 1000 scalefont setfont 0 0 moveto
  70.     /e currentfont /Encoding get def
  71.     0 1 255 {
  72.         dup e exch get
  73.         dup /.notdef ne {
  74.             exch dup printmetric
  75.         } {
  76.             pop pop
  77.         } ifelse
  78.     } for
  79.     % s contains an entry for each name in the original encoding vector
  80.     /s 256 dict def
  81.     e {
  82.         s exch true put
  83.     } forall
  84.     % v is the new encoding vector
  85.     /v 256 array def
  86.     0 1 255 {
  87.         v exch /.notdef put
  88.     } for
  89.     % fill up v with names in CharStrings
  90.     /i 0 def
  91.     currentfont /CharStrings get {
  92.         pop
  93.         i 255 le {
  94.             v i 3 -1 roll put
  95.             /i i 1 add def
  96.         } {
  97.             printv
  98.             v 0 3 -1 roll put
  99.             /i 1 def
  100.         } ifelse
  101.     } forall
  102.     printv
  103.     (EndCharMetrics) =
  104. } bind def
  105.  
  106. % name actual_code normal_code printmetric -
  107.  
  108. /printmetric {
  109.     /saved save def
  110.     (C ) print =only
  111.     ( ; WX ) print
  112.     onechar 0 3 -1 roll put
  113.     onechar stringwidth pop round cvi =only
  114.     ( ; N ) print =only
  115.     ( ; B ) print
  116.     onechar false charpath flattenpath mark pathbbox counttomark {
  117.         counttomark -1 roll
  118.         round cvi =only
  119.         ( ) print
  120.     } repeat pop
  121.     (;) =
  122.     saved restore
  123. } bind def
  124.  
  125. % fontname printafm -
  126.  
  127. /printafm {
  128.     findfont gsave setfont
  129.     (StartFontMetrics 2.0) =
  130.  
  131.         % Print the UniqueID
  132.  
  133.     currentfont /UniqueID known {
  134.         (Comment UniqueID ) print
  135.         currentfont /UniqueID get =only
  136.         (\n) print
  137.     } if
  138.  
  139.     (FontName ) print currentfont /FontName get =
  140.  
  141.         % Print the FontInfo
  142.  
  143.     currentfont /FontInfo get {
  144.         exch
  145.         dup /FSType ne {
  146.             =string cvs dup dup 0 get 0 exch toupper put print
  147.             ( ) print =
  148.         } {
  149.             pop pop
  150.         } ifelse
  151.     } forall
  152.  
  153.         % Print the FontBBox
  154.  
  155.     (FontBBox) print
  156.     currentfont /FontBBox get {
  157.         ( ) print round cvi =only
  158.     } forall
  159.     (\n) print
  160.  
  161.     printcharmetrics
  162.     (EndFontMetrics) =
  163.     grestore
  164. } bind def
  165.  
  166. % Check for command line arguments.
  167. [ shellarguments
  168.  { ] dup length 1 eq
  169.     { 0 get printafm }
  170.     { (Usage: printafm fontname\n) print flush }
  171.    ifelse
  172.  }
  173.  { pop }
  174. ifelse
  175.